﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Hospital
{
    public partial class ContractZip2 : BasePage
    {
        string orderid = "";
        HZ.Supervise.IBLL.IExecuteContext ih = HZ.Supervise.BLLFactory.ExecuteContext();
        /// <summary> 
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param> 
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["orderID"] == null)
            {
                HZ.Web.WebUtil.Alert("传值为空！", this.Page);
                return;
            }
            else
            {
                orderid = Request["orderID"].ToString();
            }
            if (!IsPostBack)
            {
                GoodsInfoDataBind();
            }
        }

        /// <summary>
        ///  绑定组件详情
        /// </summary>
        private void GoodsInfoDataBind()
        {
            int totalCount = 0;
            string s = string.Format(" and OrderID='{0}' ", Request["orderID"]);
            DataTable dt = ih.GetOrderDXSB2(s, 1, 0, out totalCount);
            if (dt.Rows.Count > 0)
            {
                if (!string.IsNullOrEmpty(dt.Rows[0]["Orderlink"].ToString()))
                {
                    //截取图片路径
                    string urls = dt.Rows[0]["Orderlink"].ToString().Substring(0, dt.Rows[0]["Orderlink"].ToString().Length - 1);
                    string[] url = urls.Split(';');
                    //创建一个新的table
                    DataTable dtNew = new DataTable();
                    dtNew.Columns.Add("Orderlink");
                    for (int i = 0; i < url.Length; i++)
                    {
                        DataRow row = dtNew.NewRow();
                        row["Orderlink"] = url[i];
                        dtNew.Rows.Add(row);
                    }
                    GetGoodsIfo(dtNew);
                }
                else
                {
                    this.DLCompany.DataSource = "";
                    this.DataBind();
                    lblpiceshouw.Visible = true;
                }
            }
            else
            {
                HZ.Web.WebUtil.Alert("您没有上传文件！", this);
            }
        }


        /// <summary>
        //通过实体赋值
        /// </summary>
        private void GetGoodsIfo(DataTable dt)
        {
            dt.Columns.Add("URL");
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                if (dt.Rows[i]["Orderlink"] != null && dt.Rows[i]["Orderlink"].ToString() != "")
                {
                    string picUrl = "";
                    string url1 = dt.Rows[i]["Orderlink"].ToString();
                    if (url1.Contains("www.hzqx.cc"))
                    {
                        picUrl = dt.Rows[i]["Orderlink"].ToString();
                    }
                    else
                    {
                        string strPicSaveName = dt.Rows[i]["Orderlink"].ToString().Substring(dt.Rows[i]["Orderlink"].ToString().LastIndexOf("/") + 1);
                        picUrl = System.Configuration.ConfigurationManager.AppSettings["iis"] + strPicSaveName;
                    }
                    dt.Rows[i]["URL"] = picUrl;
                }
            }
            DLCompany.DataSource = dt;
            DLCompany.DataBind();
            if (dt.Rows.Count <= 0)
            {
                lblpiceshouw.Visible = true;
            }
            else
            {
                lblpiceshouw.Visible = false;
            }
        }
    }
}